package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.service.impl.NursingProjectServiceImpl;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;


@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nps;

    @GetMapping
    @ApiOperation(value = "分页查询护理项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理项目名称", dataType = "string", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "integer", paramType = "query", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "integer", paramType = "query", defaultValue = "10", required = true),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "integer", paramType = "query", required = false)
    })
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(String name,Integer pageNum,
                                                                       Integer pageSize,Integer status){
        PageResponse page = nps.selectByPage(name,pageNum,pageSize,status);

        return success(page);
    }

    @PostMapping
    @ApiOperation(value = "增加护理项目")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto npd){

        nps.addNursingProject(npd);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id护理项目")
    public ResponseResult<NursingProjectVo> selectByID(@PathVariable Long id){
        NursingProjectVo npv = nps.selectByID(id);
        return success(npv);
    }

    @PutMapping
    @ApiOperation(value = "更新护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nps.updateNursingProject(nursingProjectDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目")
    public ResponseResult deleteNursingProject(@PathVariable Long id){
        nps.deleteNursingProject(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理项目")
    public ResponseResult forbiddenNursingProject(@PathVariable Long id, @PathVariable Integer status){
        nps.forbiddenNursingProject(id,status);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询护理项目")
    public ResponseResult<List<NursingProjectVo>> selectAll(){
        List<NursingProjectVo> list = nps.selectAll();
        return success(list);
    }




}
